//
//  BuyerInformationView.m
//  1243
//
//  Created by 洛水寒 on 16/5/24.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "BuyerInformationView.h"
#import "NetWorkTools.h"

@interface BuyerInformationView ()

@property (nonatomic,strong)UILabel *buyerName;
@property (nonatomic,strong)UILabel *buyerID;
@property (nonatomic,strong)UILabel *buyerOwnNum;
@property (nonatomic,strong)UILabel *buyerPrice;

@end

@implementation BuyerInformationView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
   
        [self getUserData];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    
    UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, 80, SCREEN_HEIGHT * 0.045)];
    name.text = @"购买者姓名: ";
    name.font = [UIFont systemFontOfSize:14];
    [self addSubview:name];
    
    self.buyerName = [[UILabel alloc] initWithFrame:CGRectMake(80, 5, (SCREEN_HEIGHT - 20) / 2, SCREEN_HEIGHT * 0.045)];
    self.buyerName .font = [UIFont systemFontOfSize:14];
    [self addSubview:self.buyerName ];
    
    UILabel *Id = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2, 5, 35, SCREEN_HEIGHT * 0.045)];
    Id.text = @"编号: ";
    Id.font = [UIFont systemFontOfSize:14];
    [self addSubview:Id];
    
    self.buyerID = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + 35, 5, self.size.width / 2 - 45, SCREEN_HEIGHT * 0.045)];
    self.buyerID.font = [UIFont systemFontOfSize:14];
    [self addSubview:self.buyerID];
    
    UILabel *ownNum = [[UILabel alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT * 0.045 + 5, 65, SCREEN_HEIGHT * 0.045)];
    ownNum.text = @"拥有数量: ";
    ownNum.font = [UIFont systemFontOfSize:14];
    [self addSubview:ownNum];
    
    self.buyerOwnNum = [[UILabel alloc] initWithFrame:CGRectMake(65, SCREEN_HEIGHT * 0.045 + 5, self.size.width / 2 - 55, SCREEN_HEIGHT * 0.045)];
    self.buyerOwnNum.font = [UIFont systemFontOfSize:14];
    [self addSubview: self.buyerOwnNum];
    
    
    UILabel *price = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT * 0.045 + 5, 35, SCREEN_HEIGHT * 0.045)];
    price.text = @"价值: ";
    price.font = [UIFont systemFontOfSize:14];
    [self addSubview:price];
    
    self.buyerPrice = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + 35, SCREEN_HEIGHT * 0.045 + 5, self.size.width / 2 - 45, SCREEN_HEIGHT * 0.045)];
    self.buyerPrice.font = [UIFont systemFontOfSize:14];
    self.buyerPrice.adjustsFontSizeToFitWidth = YES;
    [self addSubview:self.buyerPrice];
    
}
- (void)getUserData{
    
    NSDictionary *dict = [ReadLoginData readLoginData];
    NSString *userNumber = [dict objectForKey:@"Number"];
    NSString *UserName = [dict objectForKey:@"UserName"];
    
    NSDictionary *params2 = @{
                              //
                              @"Id":userNumber,
                              @"UserName":UserName
                              };
    
    [[NetWorkTools sharedNetWorkTools] OtherobjectWithURLDict:params2 AndMenthodName:@"getUserInfo" completeBlock:^(id object) {
        
        
        NSString *str = object[@"BackData"];
        NSArray *arr = [NetWorkTools arrayWithJsonString:str];
        NSLog(@"用户信息%@",object);
        self.buyerName.text= [NSString stringWithFormat:@"%@",arr[0][@"RealName"]];
        self.buyerID.text =[NSString stringWithFormat:@"%@",arr[0][@"UserName"]];
        self.buyerOwnNum.text =[NSString stringWithFormat:@"%@",arr[0][@"TicketQty"]];
        self.buyerPrice.text =[NSString stringWithFormat:@"%@",arr[0][@"TicketMoney"]];
        
        if (arr == nil) {
            self.buyerName.text = @"";
            self.buyerID.text = @"";
            self.buyerOwnNum.text = @"";
            self.buyerPrice.text = @"";
        }else if ([arr[0][@"RealName"] isEqual:[NSNull null]]){
            self.buyerName.text = @"";
        }else if ([arr[0][@"UserName"] isEqual:[NSNull null]]){
            self.buyerID.text = @"";
        }else if ([arr[0][@"TicketQty"] isEqual:[NSNull null]]){
            self.buyerOwnNum.text = @"";
        }else if ([arr[0][@"TicketMoney"] isEqual:[NSNull null]]){
            self.buyerPrice.text = @"";
        }
        else{
            self.buyerName.text= [NSString stringWithFormat:@"%@",arr[0][@"RealName"]];
            self.buyerID.text =[NSString stringWithFormat:@"%@",arr[0][@"UserName"]];
            self.buyerOwnNum.text =[NSString stringWithFormat:@"%@",arr[0][@"TicketQty"]];
            self.buyerPrice.text =[NSString stringWithFormat:@"%@",arr[0][@"TicketMoney"]];
        }
        [self setNeedsDisplay];
        
        
        _userName = arr[0][@"RealName"];
        _userId = arr[0][@"UserName"];
        _ownNum = [NSString stringWithFormat:@"%@", arr[0][@"TicketQty"]];
    }];
  
}

@end
